﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

/**
 * 创建时间：2014/11/13 14:09:39
 * 作者：yong.blackcore
 * Email：itblackhole@outlook.com
 * QQ：50404503
 */
namespace CUWo.Common.Converter
{
    /// <summary>
    /// 显示指定长度字符
    /// <para>一个中文字符算两个长度</para>
    /// </summary>
    public class CutStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return string.Empty;

            string s = value.ToString();
            int leng;
            if (int.TryParse(parameter.ToString(), out leng))
            {
                return new Helper().GetString(s, leng);
            }
            else
                return string.Empty;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return string.Empty;
        }
    }
}
